import client from "../utils/pool.mjs"
import { transferStore } from "../service/qiniu.mjs";
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
const map = {
}
async function restoreImage() {
    // 将数据源中的图片地址替换为七牛云存储的图片地址
    // 获取所有品牌
    const brands = await client.brand.findMany();
    console.log('brands length', brands.length)

    // 遍历每个品牌
    for (const brand of brands) {
        console.log('brand id', brand.id)
        if (brand.avatar) {
            try {
                // 转换图片地址
                const { url } = await transferStore(brand.avatar);
                // await sleep(2000);
                // 更新 logo_url 字段
                await client.brand.update({
                    where: { id: brand.id },
                    data: { logo_url: url }
                });
            } catch (e) {
                console.error(`Error updating brand ID ${brand.id}:`, e);
            }

        } else {
            console.log('brand id', brand.id, 'avatar is null')
        }

    }
}
//
// transferStore('http://image.bitauto.com/cargroup/car/20230523/297/2023052339421483384729706329.png')
//     .then(res => {
//         console.log(res)
//     })
// 使用
restoreImage();
